package com.tofindaway.hibernate.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.tofindaway.hibernate.entity.SqlTable;

@Repository
public class SqlTableDao extends AbstractDaoImp {

	@SuppressWarnings("unchecked")
	public List<SqlTable> getList() {
		List<SqlTable> list = getSession().createCriteria(SqlTable.class).list();
		return list;
	}

	public SqlTable findById(Long id) {
		SqlTable sqlTable = (SqlTable) getSession().get(SqlTable.class, id);
		return sqlTable;
	}

	public void delete(SqlTable sqlTable) {
		getSession().delete(sqlTable);
	}

	public SqlTable deleteById(Long id) {
		// is it useful ?
		SqlTable sqlTable = findById(id);
		getSession().delete(sqlTable);
		return sqlTable;
	}

	public void update(SqlTable sqlTable) {
		getSession().merge(sqlTable);
	}

	public void create(SqlTable sqlTable) {
		getSession().save(sqlTable);
	}
	
	public SqlTable load(Long id) {
		SqlTable sqlTable = (SqlTable) getSession().load(SqlTable.class, id);
		return sqlTable;
	}
}
